package servlet;

import com.google.gson.Gson;
import pojo.User;
import service.Impl.UserServiceImpl;
import service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/limit")
public class LimitServlet extends HttpServlet {

    private UserService userService = new UserServiceImpl();


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int number = Integer.parseInt(request.getParameter("pageNumber"));


        int pageNumber = 5*number;

        List<User> userList = userService.findUser(pageNumber);

        Gson gson = new Gson();
        String json = gson.toJson(userList);
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write(json);
        response.getWriter().close();

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }


}
